/*
 * RTP packet
 */

 #ifndef PACKET_H
 #define PACKET_H

#if defined(WIN32)
#include <opencv/cv.h>
#include <opencv/highgui.h>
#else
#include <cv.h>
#include <highgui.h>
#endif

#include <stdlib.h>    // for malloc
#include <stdio.h>     // for printf

#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>

#include <arpa/inet.h>

#include "cloud_helper.h"

#define MAXDATASIZE 512 // max number of bytes we can get at once

#define HEIGHT 40       // height of thumbnail
#define WIDTH 60        // width of thumbnail
#define INTERVAL_MS 40  // packet timestamp interval in ms
#define VERSION 2       // RTP protocol version
#define JPEG 26

#define MAXNUMSERVERS 5

typedef struct cloud_server cloud_server_t;

typedef struct{
    unsigned int prefix;
	unsigned int attrs;
	unsigned int timestamp;
    unsigned int ssrc;
    unsigned char* payload;
} rtp_packet;

typedef struct {
    cloud_server_t** servers;
    int num_servers;
} server_list;

typedef struct{
    IplImage *image;
    CvMat *thumb;
    CvMat *encoded;
    CvCapture *video;
} video_manager;

//void init_packet(rtp_packet* packet, video_manager* cv, unsigned int frame_num, unsigned int seq_num);
void set_buffer(unsigned char* to, unsigned char* from, unsigned long bytes);
void set_buffer_to(unsigned char* to, unsigned char from, unsigned long bytes);
unsigned char* get_rtp_packet(char* filename, int frame_num, int seq_num, server_list* s_list);
int init_video_manager(video_manager* cv, char* filename);
int get_frame(video_manager* cv, int frame_num);
void close_video(video_manager* cv);
void free_server_list(server_list* s_list);

 #endif
